<template>
  <div class="search-view">
    <div class="city-name">
      你正在预览{{ search }}的天气信息
      <span v-show="IsShow">，可以通过右上角的"+"号按钮保存起来</span>
    </div>
    <div class="info-box">
      <h1>当日气温是：{{ nowWeather.temperature }}摄氏度</h1>
      <h1>当日天气是：{{ nowWeather.weather }}</h1>
      <h1>当日风向是：{{ nowWeather.winddirection }}风</h1>
      <h1>当日风力是：{{ nowWeather.windpower }}级</h1>
    </div>
    <hr />
    <ChartComp></ChartComp>
  </div>
</template>
<script setup>
import ChartComp from '../components/ChartComp.vue'
import { useRoute } from 'vue-router'
import { getWeather } from '@/api/weather'
import { ref, onMounted, computed } from 'vue'
import { useWeatherStore } from '@/stores/WeatherStore'
const weatherStore = useWeatherStore()
const route = useRoute()
const key = route.params.key
const search = route.query.search
const nowWeather = ref({})
onMounted(async () => {
  const res = await getWeather(key, 'base')
  console.log(res)
  nowWeather.value = res.lives[0]
})
// 判断是否显示提示文字
const IsShow = computed(() => {
  return (
    route.path !== '/weather' &&
    !weatherStore.cityList.some((city) => city.adcode === route.params.key)
  )
})
</script>
<style scoped lang="scss">
.search-view {
  display: flex;
  flex-direction: column;
  background-color: #00668a;
  margin-top: 1.25rem;
  .city-name {
    padding: 0.5rem;
    height: 2.5rem;
    color: #fff;
    text-align: center;
    background-color: #004e71;
  }
  hr {
    margin-top: 1.5rem;
    border: 1px solid #2a7696;
  }
  .info-box {
    margin-top: 1.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    color: #fff;
  }
}
</style>
